<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta charset="utf-8">
    <title>修改密码</title>
    <link rel="shortcut icon" href="${pageContext.request.contextPath}/favicon.ico"/>
    <link rel="bookmark" href="${pageContext.request.contextPath}/favicon.ico"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/webjars/layui/css/layui.css" media="all">
    <script type="application/javascript" src="${pageContext.request.contextPath}/webjars/layui/layui.js"
            charset="utf-8"></script>
    <script type="application/javascript" src="${pageContext.request.contextPath}/webjars/jquery/jquery.js"></script>
    <script type="application/javascript" src="${pageContext.request.contextPath}/private/js/loading/ajaxloading.js"></script>
</head>
<body>
<form class="layui-form" action="">
    <fieldset class="layui-elem-field">
        <legend>修改密码</legend>
        <div class="layui-form-item">
            <label class="layui-form-label">旧密码：</label>
            <div class="layui-input-inline">
                <input type="password" id="password_old" name="pwdold" required lay-verify="password_old" placeholder="请输入旧密码" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">新密码：</label>
            <div class="layui-input-inline">
                <input type="password" id="password_new" name="pwdnew" required lay-verify="password_new" placeholder="请输入新密码" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" class="layui-btn" lay-submit lay-filter="modify">更改密码</button>
            </div>
        </div>
    </fieldset>
</form>

</body>
<script type="application/javascript">
    layui.use('form', function () {
        var form = layui.form;
        //表单验证规则自定义
        form.verify({
            password_old: function (value) {
                if(!value) {
                    return "用户名不能为空";
                }
            }
            ,password_new: function (value) {
                if(!value) {
                    return "密码不能为空";
                }
            }
        });

        //监听提交
        form.on('submit(modify)', function (data) {
            fn_modifypwd(data.field);
            return false;
        });
    });

    function fn_modifypwd(formdata) {
        $.ajax({
            url:'${pageContext.request.contextPath}/eyas/admin/modifypwd',
            async:true,
            data:formdata,
            dataType:'json',
            type:'PUT',
            success:function(xhrdata) {
                if(!xhrdata.success) {
                    layer.msg(xhrdata.errormsg);
                    return;
                }
                layer.msg("密码修改成功，2秒后跳转至登录页面");
                setTimeout(function(){
                    window.parent.location.href = '${pageContext.request.contextPath}/eyas/admin/logout';
                },2000);
            },
            error:function(errodata) {
                layer.msg(errodata.responseText.message);
            }
        });
    }
</script>
</html>
